package 人手一支笔ThreadLock;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class OldDemo {
    static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    static class ParseDate implements Runnable{
        int i = 0;

        @Override
        public void run() {
            try {
                Date date = simpleDateFormat.parse("2022-4-5 16:44:" + i % 60);
                System.out.println(i + ":" + date);

            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        for (int i = 0; i < 100; i++) {
            executorService.execute(new ParseDate());
        }
    }
    // 输出结果：有正确的，有报错的。说明，SimpleDateFormat不是线程安全的

    // 不懂SimpleDateFormat线程不安全原因。不懂这个例子啥意思？？
}
